$(function () {
    var tree = [
        {
            Id: 1,
            Name: "系统设置",
            Icon: "icon icon-comments",
            Url: "",
            Children: [
                {
                    Id: 2,
                    Name: "用户设置",
                    Icon: "icon icon-comments",
                    Url: "",
                    Children: [
                        {
                            Id: 3,
                            Name: "用户信息",
                            Icon: "icon icon-comments",
                            Url: "",
                        }
                    ]
                }

            ]
        },
        {
            Id: 1,
            Name: "订单管理",
            Icon: "icon icon-comments",
            Url: "",
        },
        {
            Id: 1,
            Name: "系统设置",
            Icon: "icon icon-comments",
            Url: "",
            Children: [
                {
                    Id: 2,
                    Name: "用户设置",
                    Icon: "icon icon-comments",
                    Url: "",
                    Children: [
                        {
                            Id: 3,
                            Name: "用户信息",
                            Icon: "icon icon-comments",
                            Url: "",
                        }
                    ]
                }

            ]
        },
        {
            Id: 1,
            Name: "订单管理",
            Icon: "icon icon-comments",
            Url: "",
        }
    ];

    //创建菜单
    var treeHtml = '';
    function CreateMenusHtml(params) {
        if (treeHtml === undefined) { treeHtml = ""; }
        $.each(params, function (key, value) {
            treeHtml += '<li>' +
                '<div class="menu-btn" data-id="{0}" data-url="{1}"  sortid="{2}">'.Format(value.Id, value.Url, value.SortId);
            if (value.Children) {
                treeHtml += '<span class="menu-icon"><i class="{0}"></i></span>'.Format(value.Icon);
                treeHtml += '<span class="menu-text">{0}</span>'.Format(value.Name);
                treeHtml += '<span class="menu-icon-expand"><i class="icon icon-angle-right"></i></span></div>';
                treeHtml += '<ul>';
                CreateMenusHtml(value.Children);
            } else {
                treeHtml += '<span class="menu-icon"><i class="{0}"></i></span>'.Format(value.Icon);
                treeHtml += '<span class="menu-text">{0}</span></div>'.Format(value.Name);
                //treeHtml += '<span class="menu-icon-expand"><i></i></span></div>';
            }
            treeHtml += "</ul></li>";
        })
    }


    function createMenus() {
        CreateMenusHtml(tree);
        $("#sys_menu").html(treeHtml);
    }
    createMenus();
});